var database = require('../../data/data.js');
Page({
  data: {
    flag: true
  },
  onShow: function () {
    database.homeFlag = true;
    var that = this;
    wx.getUserInfo({
      success(res) {
        that.setData({
          nickName: res.userInfo.nickName,
          avatarUrl: res.userInfo.avatarUrl,
          tel: database.tel
        })
      }
    })
    if (database.login) {
      wx.request({
        url: database.url + '/api/V2/user/get_user',
        method: "POST",
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          accessToken: database.accessToken,
          userId: database.userId
        },
        success(res) {
          database.tel = res.data.data.mobile
          that.setData({
            tel: database.tel
          })
        }
      })
    } else {
      that.setData({
        tel: "未绑定"
      })
    }
  },
  toBingding: function () {
    wx.navigateTo({
      url: '/pages/binding/binding',
    })
  },
  toAbout: function () {
    wx.navigateTo({
      url: '/pages/my/about/about',
    })
  },
  toOrders: function () {
    wx.navigateTo({
      url: '/pages/orders/orders',
    })
  },
  toApply: function () {
    wx.navigateTo({
      url: '/pages/venuesList/venuesList',
    })
  },
  toRemoveBinding: function () {
    wx.showModal({
      content: '是否解除绑定',
      success(res) {
        if (res.confirm) {
          wx.request({
            url: database.url + '/api/V2/user/relieve_wechat_small',
            method: "POST",
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            data: {
              accessToken: database.accessToken,
              unionid: database.unionid
            },
            success(res) {
              wx.showToast({
                title: res.data.status_reason,
              })
              if (res.data.status) {
                wx.switchTab({
                  url: '/pages/home/home',
                })
              }
            }
          })
        }
      }
    })
  }
})